#-*- encoding:utf-8 -*-
import threading

class Singleton(object):
    """ 单例修饰器/类 """
    _instance_lock = threading.RLock()
    def __init__(self, cls):
        self.cls = cls
        self._instance = {}
    
    def __call__(self, *args, **kwargs):
        if self.cls not in self._instance:
            with self._instance_lock:
                if self.cls not in self._instance:
                    self._instance[self.cls] = self.cls(*args, **kwargs)
        return self._instance.get(self.cls, None)